﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FANN.Net;

namespace Neural
{
    class BetNet
    {
        private NeuralNet net;

        public BetNet(uint[] layers)
        {
            net = new NeuralNet();
            net.CreateStandardArray(layers);
            net.RandomizeWeights(-0.1, 0.1);
            net.SetLearningRate(0.7f);
        }

        public void trainOnFile(string filePath)
        {
            TrainingData data = new TrainingData();
            data.ReadTrainFromFile(filePath);
            net.TrainOnData(data, 1000, 10, 0.0001f);
        }

        public void saveNet(string filePath)
        {
            net.Save(filePath);
        }


        public void openNet(string path)
        {
            net.CreateFromFile(path);
            Console.WriteLine(net.GetNumInput());
        }

        public Double[] getAnswer(string inline)
        {
            string[] substrings = inline.Split(' ');
            List<double> inarr = new List<double>();

            foreach (var str in substrings)
            {
                if (!String.IsNullOrEmpty(str))
                {

                    inarr.Add(Convert.ToDouble(str.Replace('.', ',')));
                }
                //Console.WriteLine(str);
            }

            double[] result = net.Run(inarr.ToArray());

            return result;
        }
    }
}
